package com.bumptech.glide.load.data;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore.Images.Thumbnails;
import android.provider.MediaStore.Video.Thumbnails;
import android.text.TextUtils;
import android.util.Log;
import com.bumptech.glide.Priority;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MediaStoreThumbFetcher
  implements DataFetcher<InputStream>
{
  private static final ThumbnailStreamOpenerFactory DEFAULT_FACTORY = new ThumbnailStreamOpenerFactory();
  private static final int MINI_HEIGHT = 384;
  private static final int MINI_WIDTH = 512;
  private static final String TAG = "MediaStoreThumbFetcher";
  private final Context context;
  private final DataFetcher<InputStream> defaultFetcher;
  private final ThumbnailStreamOpenerFactory factory;
  private final int height;
  private InputStream inputStream;
  private final Uri mediaStoreUri;
  private final int width;

  public MediaStoreThumbFetcher(Context paramContext, Uri paramUri, DataFetcher<InputStream> paramDataFetcher, int paramInt1, int paramInt2)
  {
    this(paramContext, paramUri, paramDataFetcher, paramInt1, paramInt2, DEFAULT_FACTORY);
  }

  MediaStoreThumbFetcher(Context paramContext, Uri paramUri, DataFetcher<InputStream> paramDataFetcher, int paramInt1, int paramInt2, ThumbnailStreamOpenerFactory paramThumbnailStreamOpenerFactory)
  {
    this.context = paramContext;
    this.mediaStoreUri = paramUri;
    this.defaultFetcher = paramDataFetcher;
    this.width = paramInt1;
    this.height = paramInt2;
    this.factory = paramThumbnailStreamOpenerFactory;
  }

  private static boolean isMediaStoreUri(Uri paramUri)
  {
    return (paramUri != null) && ("content".equals(paramUri.getScheme())) && ("media".equals(paramUri.getAuthority()));
  }

  private static boolean isMediaStoreVideo(Uri paramUri)
  {
    return (isMediaStoreUri(paramUri)) && (paramUri.getPathSegments().contains("video"));
  }

  private InputStream openThumbInputStream(ThumbnailStreamOpener paramThumbnailStreamOpener)
  {
    InputStream localInputStream1;
    try
    {
      InputStream localInputStream2 = paramThumbnailStreamOpener.open(this.context, this.mediaStoreUri);
      localInputStream1 = localInputStream2;
      int i = -1;
      if (localInputStream1 != null)
        i = paramThumbnailStreamOpener.getOrientation(this.context, this.mediaStoreUri);
      if (i != -1)
        return new ExifOrientationStream(localInputStream1, i);
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
      {
        if (Log.isLoggable("MediaStoreThumbFetcher", 3))
          Log.d("MediaStoreThumbFetcher", "Failed to find thumbnail file", localFileNotFoundException);
        localInputStream1 = null;
      }
    }
    return localInputStream1;
  }

  public void cancel()
  {
  }

  public void cleanup()
  {
    if (this.inputStream != null);
    try
    {
      this.inputStream.close();
      label14: this.defaultFetcher.cleanup();
      return;
    }
    catch (IOException localIOException)
    {
      break label14;
    }
  }

  public String getId()
  {
    return this.mediaStoreUri.toString();
  }

  public InputStream loadData(Priority paramPriority)
    throws Exception
  {
    ThumbnailStreamOpener localThumbnailStreamOpener = this.factory.build(this.mediaStoreUri, this.width, this.height);
    if (localThumbnailStreamOpener != null)
      this.inputStream = openThumbInputStream(localThumbnailStreamOpener);
    if (this.inputStream == null)
      this.inputStream = ((InputStream)this.defaultFetcher.loadData(paramPriority));
    return this.inputStream;
  }

  static class FileService
  {
    public boolean exists(File paramFile)
    {
      return paramFile.exists();
    }

    public File get(String paramString)
    {
      return new File(paramString);
    }

    public long length(File paramFile)
    {
      return paramFile.length();
    }
  }

  static class ImageThumbnailQuery
    implements MediaStoreThumbFetcher.ThumbnailQuery
  {
    private static final String[] PATH_PROJECTION = { "_data" };
    private static final String PATH_SELECTION = "kind = 1 AND image_id = ?";

    public Cursor queryPath(Context paramContext, Uri paramUri)
    {
      String str = paramUri.getLastPathSegment();
      return paramContext.getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, PATH_PROJECTION, "kind = 1 AND image_id = ?", new String[] { str }, null);
    }
  }

  static abstract interface ThumbnailQuery
  {
    public abstract Cursor queryPath(Context paramContext, Uri paramUri);
  }

  static class ThumbnailStreamOpener
  {
    private static final MediaStoreThumbFetcher.FileService DEFAULT_SERVICE = new MediaStoreThumbFetcher.FileService();
    private MediaStoreThumbFetcher.ThumbnailQuery query;
    private final MediaStoreThumbFetcher.FileService service;

    public ThumbnailStreamOpener(MediaStoreThumbFetcher.FileService paramFileService, MediaStoreThumbFetcher.ThumbnailQuery paramThumbnailQuery)
    {
      this.service = paramFileService;
      this.query = paramThumbnailQuery;
    }

    public ThumbnailStreamOpener(MediaStoreThumbFetcher.ThumbnailQuery paramThumbnailQuery)
    {
      this(DEFAULT_SERVICE, paramThumbnailQuery);
    }

    private Uri parseThumbUri(Cursor paramCursor)
    {
      String str = paramCursor.getString(0);
      boolean bool1 = TextUtils.isEmpty(str);
      Uri localUri = null;
      if (!bool1)
      {
        File localFile = this.service.get(str);
        boolean bool2 = this.service.exists(localFile);
        localUri = null;
        if (bool2)
        {
          boolean bool3 = this.service.length(localFile) < 0L;
          localUri = null;
          if (bool3)
            localUri = Uri.fromFile(localFile);
        }
      }
      return localUri;
    }

    // ERROR //
    public int getOrientation(Context paramContext, Uri paramUri)
    {
      // Byte code:
      //   0: iconst_m1
      //   1: istore_3
      //   2: aconst_null
      //   3: astore 4
      //   5: aload_1
      //   6: invokevirtual 69	android/content/Context:getContentResolver	()Landroid/content/ContentResolver;
      //   9: aload_2
      //   10: invokevirtual 75	android/content/ContentResolver:openInputStream	(Landroid/net/Uri;)Ljava/io/InputStream;
      //   13: astore 4
      //   15: new 77	com/bumptech/glide/load/resource/bitmap/ImageHeaderParser
      //   18: dup
      //   19: aload 4
      //   21: invokespecial 80	com/bumptech/glide/load/resource/bitmap/ImageHeaderParser:<init>	(Ljava/io/InputStream;)V
      //   24: invokevirtual 83	com/bumptech/glide/load/resource/bitmap/ImageHeaderParser:getOrientation	()I
      //   27: istore 10
      //   29: iload 10
      //   31: istore_3
      //   32: aload 4
      //   34: ifnull +8 -> 42
      //   37: aload 4
      //   39: invokevirtual 88	java/io/InputStream:close	()V
      //   42: iload_3
      //   43: ireturn
      //   44: astore 7
      //   46: ldc 90
      //   48: iconst_3
      //   49: invokestatic 96	android/util/Log:isLoggable	(Ljava/lang/String;I)Z
      //   52: ifeq +30 -> 82
      //   55: ldc 90
      //   57: new 98	java/lang/StringBuilder
      //   60: dup
      //   61: invokespecial 99	java/lang/StringBuilder:<init>	()V
      //   64: ldc 101
      //   66: invokevirtual 105	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   69: aload_2
      //   70: invokevirtual 108	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      //   73: invokevirtual 112	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   76: aload 7
      //   78: invokestatic 116	android/util/Log:d	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
      //   81: pop
      //   82: aload 4
      //   84: ifnull -42 -> 42
      //   87: aload 4
      //   89: invokevirtual 88	java/io/InputStream:close	()V
      //   92: iload_3
      //   93: ireturn
      //   94: astore 8
      //   96: iload_3
      //   97: ireturn
      //   98: astore 5
      //   100: aload 4
      //   102: ifnull +8 -> 110
      //   105: aload 4
      //   107: invokevirtual 88	java/io/InputStream:close	()V
      //   110: aload 5
      //   112: athrow
      //   113: astore 11
      //   115: iload_3
      //   116: ireturn
      //   117: astore 6
      //   119: goto -9 -> 110
      //
      // Exception table:
      //   from	to	target	type
      //   5	29	44	java/io/IOException
      //   87	92	94	java/io/IOException
      //   5	29	98	finally
      //   46	82	98	finally
      //   37	42	113	java/io/IOException
      //   105	110	117	java/io/IOException
    }

    public InputStream open(Context paramContext, Uri paramUri)
      throws FileNotFoundException
    {
      Cursor localCursor = this.query.queryPath(paramContext, paramUri);
      Object localObject1 = null;
      if (localCursor != null);
      try
      {
        boolean bool = localCursor.moveToFirst();
        localObject1 = null;
        if (bool)
        {
          Uri localUri = parseThumbUri(localCursor);
          localObject1 = localUri;
        }
        if (localCursor != null)
          localCursor.close();
        InputStream localInputStream = null;
        if (localObject1 != null)
          localInputStream = paramContext.getContentResolver().openInputStream(localObject1);
        return localInputStream;
      }
      finally
      {
        if (localCursor != null)
          localCursor.close();
      }
    }
  }

  static class ThumbnailStreamOpenerFactory
  {
    public MediaStoreThumbFetcher.ThumbnailStreamOpener build(Uri paramUri, int paramInt1, int paramInt2)
    {
      if ((!MediaStoreThumbFetcher.isMediaStoreUri(paramUri)) || (paramInt1 > 512) || (paramInt2 > 384))
        return null;
      if (MediaStoreThumbFetcher.isMediaStoreVideo(paramUri))
        return new MediaStoreThumbFetcher.ThumbnailStreamOpener(new MediaStoreThumbFetcher.VideoThumbnailQuery());
      return new MediaStoreThumbFetcher.ThumbnailStreamOpener(new MediaStoreThumbFetcher.ImageThumbnailQuery());
    }
  }

  static class VideoThumbnailQuery
    implements MediaStoreThumbFetcher.ThumbnailQuery
  {
    private static final String[] PATH_PROJECTION = { "_data" };
    private static final String PATH_SELECTION = "kind = 1 AND video_id = ?";

    public Cursor queryPath(Context paramContext, Uri paramUri)
    {
      String str = paramUri.getLastPathSegment();
      return paramContext.getContentResolver().query(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, PATH_PROJECTION, "kind = 1 AND video_id = ?", new String[] { str }, null);
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.bumptech.glide.load.data.MediaStoreThumbFetcher
 * JD-Core Version:    0.6.2
 */